/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sadhar.sipp.laporananggaranpendapatanuangujiantakknwisuda;

import java.util.Map;
import org.sadhar.sia.framework.ClassApplicationModule;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 * Digunakan untuk menangani komponen laporananggaranpendapatanuangujiantakknwisuda.PosPendapatanPopup,zul
 * @author kris
 */
public class PosPendapatanPopupWnd extends ClassApplicationModule {

    private Textbox txtboxPosPendapatan;
    private Textbox txtboxIdPosPendapatan;
    private Listbox lstboxPosPendapatan;
    private LaporanAnggaranPendapatanUangUjianTAKKNWisudaDAO lapuutakknwd;

    public PosPendapatanPopupWnd() {
        lapuutakknwd = new LaporanAnggaranPendapatanUangUjianTAKKNWisudaDAOImpl();
    }

    public void onCreate() throws Exception {
        Window window = (Window) this.getRoot().getFellow("contentDiv").getFirstChild();
        txtboxIdPosPendapatan = (Textbox) window.getFellow("txtboxIdPosPendapatan");
        txtboxPosPendapatan = (Textbox) window.getFellow("txtboxPosPendapatan");
        lstboxPosPendapatan = (Listbox) getFellow("lstboxPosPendapatan");
        load();
    }

    /**
     * Digunakan untuk melakukan pengisiaan data posPendapatan pada komponen lstboxPosPendapatan
     * @throws Exception
     */
    public void load() throws Exception {
        lstboxPosPendapatan.getItems().clear();
        Integer no = 1;
        for (Map map : lapuutakknwd.getAllJenisPendapatan()) {
            Listitem item = new Listitem();
            item.setValue(map);
            item.appendChild(new Listcell(String.valueOf(no++)));
            item.appendChild(new Listcell(map.get("posPendapatan").toString()));
            lstboxPosPendapatan.appendChild(item);
        }
    }

    /**
     * Digunakan untuk melakukan memasukan data idPosPendapatan dan posPendapatan pada saat
     * komponen lstboxPosPendapatan di pilih
     */
    public void lstboxPosPendapatanOnSelect() {
        Map kdTagih = (Map) lstboxPosPendapatan.getSelectedItem().getValue();
        txtboxIdPosPendapatan.setValue(kdTagih.get("idPosPendapatan").toString());
        Map nama = (Map) lstboxPosPendapatan.getSelectedItem().getValue();
        txtboxPosPendapatan.setValue(nama.get("posPendapatan").toString());
        this.detach();
    }
}
